/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SayMessageBox.java
 *
 * Created on 10.11.2009, 22:01:17
 */

package twitt;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.text.BadLocationException;
import org.jdesktop.application.Action;

/**
 *
 * @version 0.0.1.14581
 * @author Sad_hamster
 */
public class SayMessageBox extends javax.swing.JDialog {

public class ReturnMessage {
    String SendingMessage = "";
    String SendForMan = "";
    boolean SendAsPrivate = false;
  }

    String baysMessage = "Availabel symbols";
    ReturnMessage dataBack;

    public ReturnMessage GetMessageToSend() {
      return dataBack;
    }

    /** Creates new form SayMessageBox */
    public SayMessageBox(java.awt.Frame parent, boolean modal, String forWho) {
        super(parent, modal);
        initComponents();
        sayForFlag.setVisible(!forWho.equals(""));
        sayForFlag.setText("Say for " + forWho);
        sayForFlag.setSelected(!forWho.equals(""));
        dataBack = new ReturnMessage();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    availableSymvolsNote = new javax.swing.JLabel();
    jScrollPane1 = new javax.swing.JScrollPane();
    messageArray = new javax.swing.JTextPane();
    jButton2 = new javax.swing.JButton();
    jButton3 = new javax.swing.JButton();
    sayForFlag = new javax.swing.JRadioButton();
    isItPrivate = new javax.swing.JCheckBox();

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    setName("Form"); // NOI18N

    org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(twitt.TwittApp.class).getContext().getResourceMap(SayMessageBox.class);
    availableSymvolsNote.setText(resourceMap.getString("availableSymvolsNote.text")); // NOI18N
    availableSymvolsNote.setName("availableSymvolsNote"); // NOI18N

    jScrollPane1.setName("jScrollPane1"); // NOI18N

    messageArray.setName("messageArray"); // NOI18N
    messageArray.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(java.awt.event.KeyEvent evt) {
        messageArrayKeyPressed(evt);
      }
    });
    jScrollPane1.setViewportView(messageArray);

    javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(twitt.TwittApp.class).getContext().getActionMap(SayMessageBox.class, this);
    jButton2.setAction(actionMap.get("SendMessage")); // NOI18N
    jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
    jButton2.setName("jButton2"); // NOI18N

    jButton3.setAction(actionMap.get("CloseSayBox")); // NOI18N
    jButton3.setText(resourceMap.getString("jButton3.text")); // NOI18N
    jButton3.setName("jButton3"); // NOI18N

    sayForFlag.setText(resourceMap.getString("sayForFlag.text")); // NOI18N
    sayForFlag.setName("sayForFlag"); // NOI18N

    isItPrivate.setAction(actionMap.get("IsChanged")); // NOI18N
    isItPrivate.setText(resourceMap.getString("isItPrivate.text")); // NOI18N
    isItPrivate.setName("isItPrivate"); // NOI18N

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(layout.createSequentialGroup()
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 360, Short.MAX_VALUE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
              .addComponent(jButton3)
              .addComponent(jButton2, 0, 0, Short.MAX_VALUE)))
          .addComponent(availableSymvolsNote)
          .addComponent(sayForFlag)
          .addComponent(isItPrivate))
        .addContainerGap())
    );
    layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addComponent(availableSymvolsNote)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(layout.createSequentialGroup()
            .addComponent(jButton2)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jButton3))
          .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(sayForFlag)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(isItPrivate)
        .addGap(12, 12, 12))
    );

    pack();
  }// </editor-fold>//GEN-END:initComponents

    private void messageArrayKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_messageArrayKeyPressed
      // TODO add your handling code here:
      if (messageArray.getText().length() > 160) {
      try {
        messageArray.setText(messageArray.getText(0, 160));
      } catch (BadLocationException ex) {
        Logger.getLogger(SayMessageBox.class.getName()).log(Level.SEVERE, null, ex);
      }
      } 
      availableSymvolsNote.setText(baysMessage + " " + (160 - messageArray.getText().length()));
      
    }//GEN-LAST:event_messageArrayKeyPressed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                SayMessageBox dialog = new SayMessageBox(new javax.swing.JFrame(), true, "");
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
          @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

  @Action
  public void SendMessage() {
    dataBack.SendingMessage = messageArray.getText();
    if (sayForFlag.isSelected()) {
      dataBack.SendForMan = sayForFlag.getText();
    } else { dataBack.SendForMan = "";}
    dispose();
  }

  @Action
  public void CloseSayBox() {
    dataBack.SendForMan = "";
    dataBack.SendingMessage = "";
    dataBack.SendAsPrivate = false;
    dispose();
  }

  @Action
  public void IsChanged() {
    if (isItPrivate.isSelected()) {dataBack.SendAsPrivate = true;}
  }

  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JLabel availableSymvolsNote;
  private javax.swing.JCheckBox isItPrivate;
  private javax.swing.JButton jButton2;
  private javax.swing.JButton jButton3;
  private javax.swing.JScrollPane jScrollPane1;
  private javax.swing.JTextPane messageArray;
  private javax.swing.JRadioButton sayForFlag;
  // End of variables declaration//GEN-END:variables

}
